Skip to content

CachingFilteringSourceAccessor: Make the isAllowed() cache thread-safe - #16341

Merged
xokdvium merged 1 commit into
masterfrom
sync-caching-filtering-source-accessor
Sep 9, 2026
Merged

CachingFilteringSourceAccessor: Make the isAllowed() cache thread-safe#16341
xokdvium merged 1 commit into
masterfrom
sync-caching-filtering-source-accessor

Conversation

@edolstra

@edolstra edolstra commented Aug 21, 2026

Copy link
Copy Markdown
Member

Motivation

The cache in CachingFilteringSourceAccessor was a plain std::map mutated on every cache miss. With parallel evaluation, multiple eval threads can call isAllowed() on the same accessor concurrently (e.g. via builtins.readDir on a Git input fetched with exportIgnore), racing find() against emplace() and corrupting the tree. This caused segfaults like DETERMINATE-NIX-8W (a SEGV_MAPERR at offset 0x10, i.e. reading _M_left of a null red-black tree node).

Use boost::concurrent_flat_map instead, following the same pattern as CachingSourceAccessor.

Assisted-by: Claude Fable 5 noreply@anthropic.com

Context


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

The cache in CachingFilteringSourceAccessor was a plain std::map
mutated on every cache miss. With parallel evaluation, multiple eval
threads can call isAllowed() on the same accessor concurrently (e.g.
via builtins.readDir on a Git input fetched with exportIgnore), racing
find() against emplace() and corrupting the tree. This caused
segfaults like DETERMINATE-NIX-8W (a SEGV_MAPERR at offset 0x10, i.e.
reading _M_left of a null red-black tree node).

Use boost::concurrent_flat_map instead, following the same pattern as
CachingSourceAccessor.

Assisted-by: Claude Fable 5 <noreply@anthropic.com>
@github-actions github-actions Bot added the fetching Networking with the outside (non-Nix) world, input locking label Aug 21, 2026
struct CachingFilteringSourceAccessor : FilteringSourceAccessor
{
std::map<CanonPath, bool> cache;
const ref<boost::concurrent_flat_map<CanonPath, bool>> cache;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const ref<boost::concurrent_flat_map<CanonPath, bool>> cache;
std::unique_ptr<boost::concurrent_flat_map<CanonPath, bool>> cache;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@edolstra brought up that it should be fine to share the cache actually. Though this doesn't really happen in the current code base.

@edolstra
edolstra added this pull request to the merge queue Sep 9, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 9, 2026
@xokdvium
xokdvium added this pull request to the merge queue Sep 9, 2026
Merged via the queue into master with commit 19cd371 Sep 9, 2026
21 checks passed
@xokdvium
xokdvium deleted the sync-caching-filtering-source-accessor branch September 9, 2026 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fetching Networking with the outside (non-Nix) world, input locking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants